using CKS.EBE.API;
using Microsoft.SharePoint;
using System.Xml;
using Microsoft.SharePoint.Utilities;

namespace CKS.EBE.WebControls
{
    public class AdminLinks : XmlBasedControl
    {
        protected virtual void AddListLink(XmlElement oElement, string name, string listName)
        {
            SPList oList = Helper.GetListByFolderName(Web, listName);
            oElement.SetAttribute(name, oList.DefaultViewUrl);
            oElement.SetAttribute("Create" + name, oList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl);
        }

        protected override XmlDocument BuildDocument()
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.LoadXml("<AdminLinks/>");

            oDoc.DocumentElement.SetAttribute("Settings", SPUrlUtility.CombineUrl(Web.Url, "/_layouts/settings.aspx"));

            AddListLink(oDoc.DocumentElement, "Posts", Localization.GetListName(Localization.BlogList.Posts, Web.Language));
            AddListLink(oDoc.DocumentElement, "Categories", Localization.GetListName(Localization.BlogList.Categories, Web.Language));
            AddListLink(oDoc.DocumentElement, "Comments", Localization.GetListName(Localization.BlogList.Comments, Web.Language));
            AddListLink(oDoc.DocumentElement, "Links", Localization.GetListName(Localization.BlogList.Links, Web.Language));

            oDoc.DocumentElement.SetAttribute("Settings", SPUrlUtility.CombineUrl(Web.ServerRelativeUrl, "/_layouts/cks/ebe/settings.aspx"));

            return oDoc;
        }
    }
}
